﻿// <copyright file="DataResponse.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2008-10-04</date>
// <summary>Data Response</summary>

namespace opensocial
{
    using System.Windows.Browser;

    /// <summary>
    /// OpenSocial data response
    /// </summary>
    public class DataResponse
    {
        /// <summary>
        /// Initializes a new instance of the DataResponse class
        /// </summary>
        /// <param name="scriptObject">the script object</param>
        public DataResponse(ScriptObject scriptObject)
        {
            this.ScriptObject = scriptObject;
        }

        /// <summary>
        /// Gets a value indicating whether the Data response had an error
        /// </summary>
        public bool HadError
        {
            get
            {
                return (bool)this.ScriptObject.Invoke("hadError", null);
            }
        }

        /// <summary>
        /// Gets the error message
        /// </summary>
        public string ErrorMessage
        {
            get
            {
                return this.ScriptObject.Invoke("getErrorMessage", null) as string;
            }
        }

        /// <summary>
        /// Gets or sets the script object
        /// </summary>
        public ScriptObject ScriptObject { get; set; }

        /// <summary>
        /// Get a response item
        /// </summary>
        /// <param name="itemId">the item id</param>
        /// <returns>the response item</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "get", Justification = "Mirroring OpenSocial API.")]
        public ResponseItem get(string itemId)
        {
            ScriptObject itemData = this.ScriptObject.Invoke("get", itemId) as ScriptObject;

            ResponseItem item = new ResponseItem(itemData);

            return item;
        }
    }
}
